import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.List;

public class DmjMain {

    JSONArray dmJsonArray = new JSONArray();
    Boolean isGetDm = false;
    List<Imodular> imodulars = new ArrayList<Imodular>();
    MainWindow mainWindow;
    TextArea logText;
    TextField roomidText;
    Button linkBtn;
    Button cleanBut;
    ListView modularList;

    public static void main(String[] args) throws InterruptedException {

        DmjMain dmjMain = new DmjMain();
        RunWindow runWindow = new RunWindow();
        runWindow.getMainWindow(dmjMain);
        runWindow.start();
        dmjMain.mainWindow.setDmjMain(dmjMain);
        dmjMain.imodulars = InPutModular.getModularObjects(dmjMain);
    }

    public void rundm(String roomid){
        DmTool dmTool = new DmTool();
        dmTool.roomid = roomid;
        dmTool.dmjMain = this;
        isGetDm = true;
        dmTool.start();
    }

    public void newDmCallback(JSONObject dmJson){
        newLogCallback(dmJson.getString("nickname")+":",dmJson.getString("text"));
        for (Imodular imodular : imodulars){
            imodular.newDmCall(dmJson);
        }
    }

    public void newLogCallback(String logstr){
        newLogCallback("",logstr);
    }

    public void newLogCallback(String name,String logstr){
        System.out.println(name+" "+logstr);
        try {
            logText.appendText(name+" "+logstr+"\n");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
